<template>
  <div>
    <div class="div1">
      <div class="imgb">
        <router-link to="/"
          ><img src="../assets/imgs/xiaomilogo.png" alt="" class="imga"
        /></router-link>
      </div>
      <div>
        <el-button type="text">小米商城</el-button>
        <el-button type="text">MUI</el-button>
        <el-button type="text">云服务</el-button>
        <el-button type="text">协议规则</el-button>
        <el-button type="text">协议规则</el-button>
      </div>
    </div>
    <el-divider class="fenge"></el-divider>
    <div class="div2">
      <h3 class="h3">{{ Comminfo.Cname }}</h3>
    </div>
    <div class="div3">
      <div class="divlift">
        <el-carousel trigger="click" height="570px">
          <el-carousel-item
            :autoplay="false"
            v-for="(item, index) in imginfo"
            :key="index"
          >
            <img :src="item.Mnaem" alt="" class="lunimg" />
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="divright">
        <h2>{{ Comminfo.Cname }}</h2>
        <p>{{ Comminfo.Ctxt }}</p>
        <p>¥{{ Comminfo.Cprice }}</p>
        <el-divider class="fenge"></el-divider>
        <div>选择版本</div>
        <div style="margin-top: 20px">
          <el-radio v-model="radio1" label="1" border>12GB+256GB</el-radio>
          <el-radio v-model="radio1" label="2" border>12GB+128GB</el-radio>
        </div>
        <el-divider class="fenge3"></el-divider>
        <div>选择颜色</div>
        <div style="margin-top: 20px">
          <el-radio v-model="radio2" label="1" border>雾白</el-radio>
          <el-radio v-model="radio2" label="2" border>玄黑</el-radio>
        </div>
        <el-divider class="fenge3"></el-divider>
        <div>
          <el-button class="butten1" @click="AddCat()">点击立即购买</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      radio1: "1",
      radio2: "1",
      Comminfo: {}, //详情
      imginfo: {}, //轮播图
      Cart: {
        SMid: this.$route.query.Cid,
        Suid: sessionStorage.getItem("Uid"),
      },
    };
  },
  created: function () {
    this.showImgs();
    this.showComminfo();

    this.Uid = sessionStorage.getItem("Uid");
    this.Cid = this.$route.query.Cid;
  },
  methods: {
    showComminfo() {
      this.$axios
        .get(
          "http://localhost:16673/api/Commod/ShowCommodl?Cid=" +
            this.$route.query.Cid
        )
        .then((res) => {
          this.Comminfo = res.data[0];
        });
    },
    showImgs() {
      this.$axios
        .get(
          "http://localhost:16673/api/Commod/showimgs?Cid=" +
            this.$route.query.Cid
        )
        .then((res) => {
          this.imginfo = res.data;
        });
    },
    AddCat() {
      this.$axios
        .post("http://localhost:16673/api/Cart/AddCart", this.Cart)
        .then((res) => {
          if (res.data > 0) {
            alert("已添加至购物车");
            this.$router.push("/CommInfo")
          } else {
            alert("添加至购物车失败");
          }
        });
    },
  },
};
</script>

<style scoped>
.div1 {
  margin: 0 auto;
  width: 1220px;
  height: 100px;
  margin-top: 8px;
}
.div2 {
  width: 1545px;
  margin: 0 auto;
  margin-left: -18px;
  height: 45px;
  box-shadow: 0 20px 20px 0px rgb(0, 0, 0, 0.1);
  /* 0, 0, 0, 0.1 */
  margin-top: -15px;
}
.imgb {
  float: left;
  margin-top: 5px;
}
.el-button {
  float: left;
  color: black;
  margin-top: 25px;
  font-size: 20px;
  margin-left: 80px;
}
.fenge {
  margin-top: 0px;
}
.fenge3 {
  margin-top: 20px;
}
.butten1 {
  font-size: 15px;
  background-color: #f16100;
  float: left;
  margin-top: 20px;
  color: white;
  margin-left: 0px;
}
.h3 {
  margin-top: 0px;
  float: left;
  margin-left: 30px;
}
.div3 {
  margin-top: 20px;
}
.divlift {
  width: 600px;
  height: 400px;
  float: left;
  margin-left: 120px;
  margin-top: 15px;
}
.divright {
  width: 600px;
  height: 650px;
  float: right;
  margin-right: 130px;
  margin-top: 30px;
}

.lunimg {
  width: 600px;
}
.imga {
  float: left;
  width: 80px;
}
</style>
<style >
/* 去掉radio小圆点 */
.el-radio__input {
  display: none;
}
.el-radio {
  width: 200px;
}
</style>